﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.Designer.Shell
{
    /// <summary>
    /// CaptionButtons.xaml 的交互逻辑
    /// </summary>
    public partial class CaptionButtons : UserControl
    {
        private Window _parent;
        public CaptionButtons()
        {
            InitializeComponent();
            this.Loaded += CaptionButtonsLoaded;
        }
        void CaptionButtonsLoaded(object sender, RoutedEventArgs e)
        {
            _parent = GetTopParent();
            _parent.StateChanged += MainWindow_StateChanged;
        }
        private Window GetTopParent()
        {
            return Window.GetWindow(this);
        }
        private void MainWindow_StateChanged(object sender, EventArgs e)
        {
            if (_parent.WindowState == WindowState.Maximized)
            {
                _ctlMax.Style = Resources["btnRestoreStyle"] as Style;
            }
            else
            {
                _ctlMax.Style = Resources["btnMaxStyle"] as Style;
            }
        }

        private void _ctlClose_Click(object sender, RoutedEventArgs e)
        {
            _parent.Close();
        }

        private void _ctlMax_Click(object sender, RoutedEventArgs e)
        {
            if (_parent.WindowState == WindowState.Maximized)
            {
                _parent.WindowState = System.Windows.WindowState.Normal;
            }
            else
            {
                _parent.WindowState = System.Windows.WindowState.Maximized;
            }
        }

        private void _ctlMin_Click(object sender, RoutedEventArgs e)
        {
            _parent.WindowState = WindowState.Minimized;
        }
    }
}
